package gamecontroler;

import java.util.ArrayList;
import java.util.List;

import Ultilies.OptionSettings;
import android.graphics.PointF;
import boidAlgorithms.implement.Boid;
import boidAlgorithms.implement.Herd;
import boidAlgorithms.interfaces.IBoid;
import boidAlgorithms.interfaces.IForceField;
import boidAlgorithms.interfaces.IHerd;
import boidAlgorithms.interfaces.IObstacle;
import boidAlgorithms.interfaces.IRoute;
import boidAlgorithms.math.Vector2D;

// this class used for store the information of all objects and options
// no deal with drawings
// touch signal from MainActivity that change each object's attributes, updates in here

public class GameState {

	private static final Vector2D LEFT = new Vector2D(300f, 120f);
	private static final Vector2D RIGHT = new Vector2D(800f, 120f) ;
	private static int counter=0;
	// option setting in here!
	private static OptionSettings optionSettings = new OptionSettings();

	// store the list of external objects
	private List<IRoute> routesList = new ArrayList<IRoute>();
	private List<IForceField> fieldsList = new ArrayList<IForceField>();
	private List<IObstacle> obstaclesList = new ArrayList<IObstacle>();

	// all the boid store in here
	private List<IBoid> boidList = new ArrayList<IBoid>();

	// control the herd movements
	private IHerd herd;
	
	private static Vector2D center= new Vector2D(160f, 120f);

	private GameState() {
		
		//		routesList.add(new Route());
//		fieldsList.add(new ForceField());
//		obstaclesList.add(new Obstacle());
		boidList.add(new Boid(LEFT));
		boidList.add(new Boid(RIGHT));
		herd = new Herd(boidList);
	}
	
	public static GameState getGameState() {
		if (counter==0){ 
			counter++;
			return new GameState();
		}
		else return null;
	}
	
	public static void killGameState(){
		counter=0;
	}

	public void updateBoid(int boidID, PointF p) {
		boidList.get(boidID).manualsetPosition(p);
	}

	public List<IRoute> getRoutesList() {
		return routesList;
	}

	public List<IForceField> getFieldsList() {
		return fieldsList;
	}

	public List<IObstacle> getObstaclesList() {
		return obstaclesList;
	}

	public List<IBoid> getBoidList() {
		return boidList;
	}

	public IHerd getHerd() {
		return herd;
	}

	public static OptionSettings getOptionSetting() {
		// TODO Auto-generated method stub
		return optionSettings;
	}

	public void changeBoidTarget(PointF p) {
		// TODO Auto-generated method stub
		for (int i = 0; i < boidList.size(); i++) {
			IBoid boid=boidList.get(i);
			boid.aimAt(p);
		}
	}

	public void moveBoid() {
		// TODO Auto-generated method stub
		for (int i = 0; i < boidList.size(); i++) {
			IBoid boid=boidList.get(i);
			boid.aimAt();
		}
	}

}
